package com.zyd.shiro.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zyd.shiro.business.service.TermService;
import com.zyd.shiro.business.vo.TermConditionVO;
import com.zyd.shiro.persistence.beans.School;
import com.zyd.shiro.persistence.beans.Term;
import com.zyd.shiro.persistence.mapper.TermMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

@Service
public class TermServiceImpl implements TermService {

    @Autowired
    private TermMapper termMapper;

    @Override
    public PageInfo<Term> findPageBreakByCondition(TermConditionVO vo) {
        PageHelper.startPage(vo.getPageNumber(), vo.getPageSize());
        List<Term> terms = termMapper.findPageBreakByCondition(vo);
        if (CollectionUtils.isEmpty(terms)) {
            return null;
        }
        PageInfo bean = new PageInfo<Term>(terms);
        bean.setList(terms);
        return bean;
    }

    @Override
    public int updateTermStatus(Long id, Integer status) {
        return termMapper.updateTermStatus(id,status);
    }

    @Override
    public List<Term> selectTermList() {
        return termMapper.selectTermList();
    }

    @Override
    public Term insert(Term entity) {
        Assert.notNull(entity, "Term不可为空！");
        entity.setCreateTime(new Date());
        entity.setUpdateTime(new Date());
        termMapper.insert(entity);
        return entity;
    }

    @Override
    public void insertList(List<Term> entities) {

    }

    @Override
    public boolean removeByPrimaryKey(Long primaryKey) {
        return termMapper.deleteByPrimaryKey(primaryKey) > 0;
    }

    @Override
    public boolean update(Term entity) {
        return false;
    }

    @Override
    public boolean updateSelective(Term entity) {
        Assert.notNull(entity, "Term不可为空！");
        entity.setUpdateTime(new Date());
        return termMapper.updateByPrimaryKey(entity) > 0;
    }

    @Override
    public Term getByPrimaryKey(Long primaryKey) {
        Assert.notNull(primaryKey, "PrimaryKey不可为空！");
        Term term = termMapper.selectByPrimaryKey(primaryKey);
        return null == term ? null : term;
    }

    @Override
    public Term getOneByEntity(Term entity) {
        return null;
    }

    @Override
    public List<Term> listAll() {
        return null;
    }

    @Override
    public List<Term> listByEntity(Term entity) {
        return null;
    }


}
